import router from "koa-router";
import EventModel from "../model/EventModel";
import { BaseRes } from "../res-model";

const indexRouter = new router({
  prefix: "/api",
});

indexRouter.get("/db-check", async (ctx, nenxt) => {
  let err = "db connect success";
  let mongodbConn = false;
  try {
    await EventModel.findOne();
    mongodbConn = true;
  } catch (error) {
    err = "db connect fail";
    mongodbConn = false;
  }

  ctx.body = new BaseRes({ code: 0, message: err });
  ctx.status = mongodbConn ? 200 : 500;
});

export default indexRouter;
